/*
 * @(#) SsmDaoImpl .java  1.0  2004-4-12
 *
 * Copyright 2003 by LongTop Corporation.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * LongTop Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with LongTop.
 */
package com.cnc.ssm.dao;

import com.cnc.bas.dao.DAServiceImpl;
import com.cnc.ssm.model.PwCodeType;
import com.cnc.ssm.model.PwOper;

import org.springframework.dao.DataAccessException;

import java.util.List;

/**
 * User: Du bf
 * Date: 2004-10-11
 */
public class SsmDaoImpl extends DAServiceImpl implements ISsmDao {
    public PwOper getOperatorInfo(String userName) throws DataAccessException {
        return (PwOper) this.load(PwOper.class, userName);
    }

    public List listMenu(String menuCode) throws DataAccessException {
        if (!menuCode.equals(""))
            return this.getHibernateTemplate().find("from PwMenu  where menu_parent=? order by menu_order", new Object[]{menuCode});
        else
            return this.getHibernateTemplate().find("from PwMenu  where menu_parent is null order by menu_order");

    }

    public List listFunc(String menuCode) throws DataAccessException {
        return this.getHibernateTemplate().find("from PwFunc where menu_code=? order by func_code", new Object[]{menuCode});

    }

    public List listRole(String operCode) throws DataAccessException {
        return this.getHibernateTemplate().find("from PwOperRole where oper_code=? order by role_code", new Object[]{operCode});
    }

    public List listOper(String rolecode) throws DataAccessException {
        return this.getHibernateTemplate().find("from PwOperRole where role_code=? order by oper_code", new Object[]{rolecode});
    }

    public List listCodeType() throws DataAccessException {
        return this.getHibernateTemplate().find("from PwCodeType");
    }

    public List listCodeInfo(String codeType) throws DataAccessException {
        return this.getHibernateTemplate().find("from PwCodeInfo where code_type=?  order by code_type,code_value", new Object[]{codeType});
    }

    public PwCodeType loadCodeType(String codeType) {
        return (PwCodeType) this.load(PwCodeType.class, codeType);
    }

    public void updateCodeType(PwCodeType pwCodeType) {
        this.update(pwCodeType);
    }

    public List listEmployee(String keywords) {
        if (keywords == null || keywords.equals(""))
            return this.getHibernateTemplate().find("from PwEmployee");
        keywords = "%" + keywords + "%";
        return this.getHibernateTemplate().find("from PwEmployee where empl_code like ? or empl_name like ?",
                new Object[]{keywords, keywords});
    }
}
